package lanQiaoBei.基础算法.前缀和.差分;

import java.io.*;

/*
 * “二维前缀和”——输入一个n*m(1~1000)的矩阵，再输入q个操作每个操作包含5个整数x1,y1,x2,y2,c
 * (x1,y1)(x2,y2)表示一个子矩阵的左上角和右下角
 * 每个操作表示子矩阵中的每个元素加上c
 * 请你完成所有操作后输出该子矩阵
 * */
public class P2 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static int N = 1010;
    static int n, m, q;
    static int[][] a = new int[N][N];
    static int[][] b = new int[N][N];

    public static void main(String[] args) throws Exception {
        scan();
        while (q-- > 0) {
            String[] ss = br.readLine().split(" ");
            int x1 = Integer.parseInt(ss[0]),
                    y1 = Integer.parseInt(ss[1]),
                    x2 = Integer.parseInt(ss[2]),
                    y2 = Integer.parseInt(ss[3]),
                    c = Integer.parseInt(ss[4]);
            insert(x1, y1, x2, y2, c);
        }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                b[i][j] = b[i][j - 1] + b[i - 1][j] - b[i - 1][j - 1]+b[i][j];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++)
                System.out.print(b[i][j] + " ");
            System.out.println();
        }
        return;
    }
    public static void scan() throws Exception {
        String[] ss = br.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        q = Integer.parseInt(ss[2]);
        for (int i = 1; i <= n; i++) {
            ss = br.readLine().split(" ");
            for (int j = 1; j <= m; j++) {
                a[i][j] = Integer.parseInt(ss[j - 1]);
                insert(i, j, i, j, a[i][j]);
            }
        }
    }

    private static void insert(int x1, int y1, int x2, int y2, int c) {
            b[x1][y1]+=c;
            b[x1][y2+1]-=c;
            b[x2+1][y1]-=c;
            b[x2+1][y2+1]+=c;
    }
}
